package com.changhong;

/**
 * Created by Administrator on 2018/12/13
 */
public class SortTools {

    public static int[] genData(int size) {
        int[] data = new int[size];
        for (int i = 0; i < size; i++) {
            data[i] = (int) (Math.random() * 100);
        }
        return data;
    }

    public static void swap(int[] data, int x, int y) {
        int length = data.length;
        if (x < 0 || y < 0 || x > length - 1 || y > length - 1)
            throw new IllegalArgumentException();

        int temp = data[x];
        data[x] = data[y];
        data[y] = temp;
    }

    public static void print(int[] data) {
        if (data == null) return;
        for (int i = 0; i < data.length; i++) {
            if (i < data.length - 1) {
                System.out.print(String.format("%02d", data[i]) + " ");
            } else {
                System.out.println(String.format("%02d", data[i]));
            }
        }
    }
}
